<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="企业认证信息" prop="enterpriseCertification.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择企业认证信息"
            labelName = 'enterpriseFullName'
            labelValue = 'id'
            :value = "inputForm.enterpriseCertification.id"
            :limit="1"
            @getValue='(value) => {inputForm.enterpriseCertification.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'enterpriseFullName',
              label: '企业全称'
            },
            {
              prop: 'unifiedSocialCreditCode',
              label: '统一社会信用代码'
            },
            {
              prop: 'officeArea',
              label: '办公区域'
            },
            {
              prop: 'officeAddress',
              label: '办公地址'
            }
            ]"
            :searchs="[
            {
              prop: 'enterpriseFullName',
              label: '企业全称'
            },
            {
              prop: 'unifiedSocialCreditCode',
              label: '统一社会信用代码'
            },
            {
              prop: 'officeArea',
              label: '办公区域'
            },
            {
              prop: 'officeAddress',
              label: '办公地址'
            }
            ]"
            dataListUrl="/p_enterprisecertification/pEnterpriseCertification/list"
            entityBeanName="pEnterpriseCertification"
            queryEntityUrl="/p_enterprisecertification/pEnterpriseCertification/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="内部KeyNo" prop="keyNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.keyNo" placeholder="请填写内部KeyNo"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业名称" prop="name"
                :rules="[
                 ]">
              <el-input v-model="inputForm.name" placeholder="请填写企业名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工商注册号" prop="no"
                :rules="[
                 ]">
              <el-input v-model="inputForm.no" placeholder="请填写工商注册号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登记机关" prop="belongOrg"
                :rules="[
                 ]">
              <el-input v-model="inputForm.belongOrg" placeholder="请填写登记机关"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="法定代表人ID" prop="operId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.operId" placeholder="请填写法定代表人ID"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="法定代表人名称" prop="operName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.operName" placeholder="请填写法定代表人名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="成立日期" prop="startDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.startDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="吊销日期" prop="endDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.endDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登记状态" prop="status"
                :rules="[
                 ]">
              <el-input v-model="inputForm.status" placeholder="请填写登记状态"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="省份" prop="province"
                :rules="[
                 ]">
              <el-input v-model="inputForm.province" placeholder="请填写省份"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="更新日期" prop="updatedDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.updatedDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="统一社会性用代码" prop="creditCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.creditCode" placeholder="请填写统一社会性用代码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="注册资本" prop="registCapi"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registCapi" placeholder="请填写注册资本"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业类型" prop="econKind"
                :rules="[
                 ]">
              <el-input v-model="inputForm.econKind" placeholder="请填写企业类型"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="注册地址" prop="address"
                :rules="[
                 ]">
              <el-input v-model="inputForm.address" placeholder="请填写注册地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="经营范围" prop="scope"
                :rules="[
                 ]">
              <el-input v-model="inputForm.scope" placeholder="请填写经营范围"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="营业期限始" prop="termStart"
                :rules="[
                 ]">
              <el-input v-model="inputForm.termStart" placeholder="请填写营业期限始"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="营业期限至" prop="teamEnd"
                :rules="[
                 ]">
              <el-input v-model="inputForm.teamEnd" placeholder="请填写营业期限至"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="核准日期" prop="checkDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.checkDate" placeholder="请填写核准日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="组织机构代码" prop="orgNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.orgNo" placeholder="请填写组织机构代码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否上市" prop="isOnStock"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.isOnStock">
                        <el-radio v-for="item in $dictUtils.getDictList('')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="股票代码" prop="stockNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.stockNumber" placeholder="请填写股票代码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="企业Logo地址" prop="imageUrl"
                :rules="[
                 ]">
              <el-upload ref="imageUrl"
              v-if="visible"
              list-type="picture-card"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/p_enterprisebusiness/pEnterpriseBusiness`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file, fileList) => {
                        $alert(`<img style='width:100%' src=' ${(file.response && file.response.url) || file.url}'/>`,  {
                          dangerouslyUseHTMLString: true,
                          showConfirmButton: false,
                          closeOnClickModal: true,
                          customClass: 'showPic'
                        });
                    }"
                    :on-success="(response, file, fileList) => {
                       inputForm.imageUrl = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.imageUrl = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="imageUrlArra">
                    <i class="el-icon-plus"></i>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业性质" prop="entType"
                :rules="[
                 ]">
                    <el-radio-group v-model="inputForm.entType">
                        <el-radio v-for="item in $dictUtils.getDictList('')" :label="item.value" :key="item.id">{{item.label}}</el-radio>
                    </el-radio-group>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="实缴资本" prop="recCap"
                :rules="[
                 ]">
              <el-input v-model="inputForm.recCap" placeholder="请填写实缴资本"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="行政区划代码" prop="areaCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.areaCode" placeholder="请填写行政区划代码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        imageUrlArra: [],
        inputForm: {
          id: '',
          enterpriseCertification: {
            id: ''
          },
          keyNo: '',
          name: '',
          no: '',
          belongOrg: '',
          operId: '',
          operName: '',
          startDate: '',
          endDate: '',
          status: '',
          province: '',
          updatedDate: '',
          creditCode: '',
          registCapi: '',
          econKind: '',
          address: '',
          scope: '',
          termStart: '',
          teamEnd: '',
          checkDate: '',
          orgNo: '',
          isOnStock: '',
          stockNumber: '',
          imageUrl: '',
          entType: '',
          recCap: '',
          areaCode: '',
          remarks: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建企业工商信息`
        } else if (method === 'edit') {
          this.title = '修改企业工商信息'
        } else if (method === 'view') {
          this.title = '查看企业工商信息'
        }
        this.imageUrlArra = []
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/p_enterprisebusiness/pEnterpriseBusiness/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.pEnterpriseBusiness)
              this.inputForm.imageUrl.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.imageUrlArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/p_enterprisebusiness/pEnterpriseBusiness/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>